        TITL DAI FIRMWARE 3EA00-3EB25  V1.1
        ORG   :EA00
*
*
*
*  =================
*** UTILITY PACKAGE ***
*  =================
*
**************
* (not used) *
**************
*
L3E158  POP   H
        JMP   L3E160
*
*********************
* RETURN AFTER 'GO' *
*********************
*
L3E159  PUSH  H         Returnaddr after 'GO'
        LXI   H,:BADC   Dummy 'saved PC' to prevent
 REM continuation 'G' with start
 REM address
        XTHL            Returnaddr in HL
L3E160  SHLD  HLSAV     Save HL
        POP   H         in HL: #BADC
 REM Into initialisation
*
**********************
* INITIALISE UTILITY *
**********************
*
* CPU registers are saved in the utility work
* area. Input from the keyboard is awaited.
*
* The address EA42 is the general return address
* for all Utility commands.
*
CALRX   SHLD  PCSAV     Save PC (next instr)
        PUSH  PSW
        POP   H
        SHLD  AFSAV     Save PSW
        LXI   H,:0000
        DAD   SP
        SHLD  SPSAV     Save SP
        XCHG
        SHLD  DESAV     Save DE
        MOV   H,B
        MOV   L,C
        SHLD  BCSAV     Save BC
        CALL  L3E238    Invert nibbles in CPU
 REM reg save area
        LHLD  PCSAV     Get addr next instr
        MOV   A,H
        ORA   L
        JZ    L3E162    If it is 0000 (entry from
 REM BASIC)
 REM Else:
        DCX   H         HL on addr current instr
        MOV   A,M       Get opcode in A
        ANI   :C7
        CPI   :C7
        JNZ   L3E162    Jump if instr is a RST
        SHLD  PCSAV     Save addr next instr
L3E162  LXI   H,MSGSO   Startaddr string table
        CALL  L3E211    Print 'PC UTILITY V3.3'
 REM
* UT command look-up:
 REM
L3E163  CALL  LCRLF     Print car.ret
        MVI   C,:3E
        CALL  CO        Print '>'
        CALL  CIE       Get keyb input, print char
        LXI   H,L3E163  Returnaddr in HL
        PUSH  H         Save it on stack
        LXI   H,CMDTB-1 Startaddr table commands
L3E164  INX   H
        CMP   M         Compare input with table
        JC    ERROR     Error if invalid input
        INX   H         )
        MOV   E,M       ) Get pointer to address
        INX   H         ) of part. routine in DE
        MOV   D,M       )
        JNZ   L3E164    Check with next command
        XCHG            Startaddr routine in HL
        PCHL            Go to this routine
*
*********
* ERROR *
*********
*
* The only error message in utility is '?'.
*
* Exit: B preserved, AFCDEHL corrupted.
*
ERROR   CALL  LCRLF     Print car.ret
        MVI   C,:3F
        CALL  CO        Print '?'
ERRST   LHLD  SPSAV     Get saved SP
        SPHL            Restore stackpointer
        NOP 
        NOP 
        NOP 
        JMP   L3E163    Start again for new input
*
********************
* ENTRY FROM BASIC *
********************
*
RESET   SHLD  HLSAV     Save HL
        LXI   H,:0000   Addr next instr (dummy)
        JMP   CALRX     Init utility
*
*************************
* UTILITY SCREEN HEADER *
*************************
*
* 0C is clear screen; 20 is space.
*
MSGSO   DATA  :0C
        DATA  :50       P
        DATA  :43       C
        DATA  :20
        DATA  :55       U
        DATA  :54       T
        DATA  :49       I
        DATA  :4C       L
        DATA  :49       I
        DATA  :54       T
        DATA  :59       Y
        DATA  :20
        DATA  :56       V
        DATA  :33       3
        DATA  :2E       .
        DATA  :33       3
*
        DATA  :00       End table
*
*******************************
* TABLE WITH UTILITY COMMANDS *
*******************************
*
CMDTB   DATA  :42       B
        DBL   RINIT     return addr to Basic
*
        DATA  :44       D
        DBL   DISPK     startaddr Display
*
        DATA  :46       F
        DBL   FILLK     startaddr Fill
*
        DATA  :47       G
        DBL   GOK       startaddr Go
*
        DATA  :4C       L
        DBL   LOOKK     startaddr Look
*
        DATA  :4D       M
        DBL   MOVEK     startaddr Move
*
        DATA  :52       R
        DBL   RHEXK     startaddr Read
*
        DATA  :53       S
        DBL   SUBSK     startaddr Substitute
*
        DATA  :56       V
        DBL   VECXK     startaddr Vector Examine
*
        DATA  :57       W
        DBL   L3E341    startaddr Write
*
        DATA  :58       X
        DBL   EXAMK     startaddr Examine
*
        DATA  :5A       Z
        DBL   ZEROK     startaddr Reset
*
        DATA  :FF       End table
*
***************
* D - DISPLAY *
***************
*
* Displays contents of memory. Two address values
* are required which specify the range of memory
* to be displayed. Break will abort the print out.
*
* Exit: CY=1, All registers corrupted.
*
DISPK   MVI   C,:02     Nr of addr inputs required
        CALL  ADARG     Get laddr and haddr on stack
        DCR   C
        JP    ERROR     Error if only 1 addr given
        POP   D         Haddr in DE
        POP   H         Laddr in HL
 REM
* Direct call entry:
 REM
*DISL1
DISP    CALL  LCRLF     Print car.ret
        CALL  LADDR     Print laddr in ASCII
DISL2   CALL  LSP       Print space
        MOV   A,M       Get contents laddr
        CALL  LBYTE     Print it in ASCII
        CALL  INXCK     INX H; check if ready
        RC              Quit if ready
        CALL  BREAK     Scan for Break pressed,
 REM abort if pressed.
        MOV   A,L
        ANI   :0F       Last instr on line?
        JZ    DISL1     Then car.ret and continue
        JMP   DISL2     Next addr
*
**************************
* ADDRESS ARGUMENT INPUT *
**************************
*
* The keyboard is scanned and the inputs are
* evaluated.
* (C) address arguments will be input and put on
* stack (LIFO). On return, C contains the
* difference between number entered and number
* desired. At least one argument is returned.
* Only the last 4 hex characters are used for the
* address value. Arguments are delimited by a
* space. The entry is terminated by CR, ESC, last
* argument or an invalid character (then error
* exit). Escape returns with CY set.
*
* Entry: C: max. nr of datablocks/addresses.
* Exit:  B: Last character typed in (terminator).
*        AFHL corrupted, DE preserved.
*
ADALT   XRA   A         A=0
        CMP   C         Max nr of inputs reached?
        RZ              Then return
ADARG   LXI   H,:0000
ADACL   CALL  CIE       Scan keyb, print char
        MOV   B,A       Store char in B
        CALL  ASHEX     Convert it to hex
        JC    ADADC     If char not 0-F: check if
 REM delimiter
ADACE   DAD   H         )
        DAD   H         ) Move bits 1 nibble
        DAD   H         ) (compose addr from inputs)
        DAD   H         )
        ADD   L         Add hex char to L
        MOV   L,A       and store it
        JMP   ADACL     Next char
 REM
* Check for delimiter/terminator:
 REM
ADADC   XTHL            Save given addr on stack
        PUSH  H         Save returnaddr again
        DCR   C         decr input counter
        MOV   A,B       Get char last input
        CPI   :20       Space ?
        JZ    ADALT     Then get next addr
        CPI   :0D       Car.ret ?
        RZ              Then ready
        CPI   :12       Escape?
        STC             Then CY=1
        RZ              and return
        JMP   ERROR     Else goto Error
 REM
* As ADARG, but carry return if 1st character is
* not a legal hex digit:
 REM
ADART   LXI   H,:0000   Immediate delimiter
        CALL  CIE       Scan keyb, print char
        MOV   B,A       Store char in B
        CALL  ASHEX     Convert it to hex
        RC              Return if no hex char
        JMP   ADACE     Into previous routine
*
* CONVERT NUMBER FROM ASCII TO HEX-VALUE:
*
* Entry: Character in A (bit 7 must be 0).
* Exit:  CY=0: Hex-value in A.
*        CY=1: Input was not 0-F; (A) useless.
*        BCDEHL preserved.
*
ASHEX   SUI   :30
        RC              Error if #00-#2F
        CPI   :0A
        JC    ASHCC     O.K. if number 0-9
        SUI   :07
        CPI   :0A
        RC              Error if #3A-#3F
        CPI   :10
ASHCC   CMC             O.K. if 0-9, A-F
        RET 
*
*
*
        UNL
HLSAV   EQU   :0059
PCSAV   EQU   :005D
AFSAV   EQU   :0053
SPSAV   EQU   :005B
DESAV   EQU   :0057
BCSAV   EQU   :0055
L3E238  EQU   :EDE7
L3E211  EQU   :ED2F
LCRLF   EQU   :ED3A
CO      EQU   :EEB4
CIE     EQU   :ED06
RINIT   EQU   :C7A0
FILLK   EQU   :ED48
GOK     EQU   :ED8A
LOOKK   EQU   :EB26
MOVEK   EQU   :EC83
RHEXK   EQU   :EF0F
SUBSK   EQU   :ED5C
VECXK   EQU   :ED77
L3E341  EQU   :EEE4
EXAMK   EQU   :ED6E
ZEROK   EQU   :ECBA
LADDR   EQU   :ED18
LSP     EQU   :ED01
LBYTE   EQU   :ED1D
INXCK   EQU   :ED80
BREAK   EQU   :EEC2
DISL1   EQU   :EABE
        LST
        END 
